package com.dietdroid;

import java.util.ArrayList;

public class FoodItemDataBase {
	
	private ArrayList<FoodItem> foodItems = new ArrayList<FoodItem>();
	
	public FoodItemDataBase() {
		
		FoodItem PopTarts = new FoodItem();
		PopTarts.setFood_name("Pop Tarts");
		PopTarts.setBarcode("038000376733");
		PopTarts.setCalories(200);
		PopTarts.setCholesterol(0);
		ArrayList<String> poptartIng = new ArrayList<String>();
		poptartIng.add("soybean");
		poptartIng.add("wheat");
		PopTarts.setIngredients(poptartIng);
		PopTarts.setProtein(2);
		PopTarts.setServing_size("1 Pastry");
		PopTarts.setSodium(170);
		PopTarts.setTotal_carbs(38);
		PopTarts.setSugars(5);
		PopTarts.setTotal_fat(5);
		
		foodItems.add(PopTarts);
		
		FoodItem Goldfish = new FoodItem();
		Goldfish.setFood_name("Goldfish");
		Goldfish.setBarcode("1410009655");
		Goldfish.setCalories(140);
		Goldfish.setCholesterol(1);
		ArrayList<String> goldfishIng = new ArrayList<String>();
		goldfishIng.add("wheat");
		goldfishIng.add("cheddar cheese");
		Goldfish.setIngredients(goldfishIng);
		Goldfish.setProtein(4);
		Goldfish.setServing_size("55 pieces");
		Goldfish.setSodium(250);
		Goldfish.setTotal_carbs(20);
		Goldfish.setSugars(5);
		Goldfish.setTotal_fat(5);
		
		foodItems.add(Goldfish);
		
		FoodItem YellowRice = new FoodItem();
		YellowRice.setFood_name("Goya Yellow Rice");
		YellowRice.setBarcode("4133102685");
		YellowRice.setCalories(160);
		YellowRice.setCholesterol(0);
		ArrayList<String> yellowRiceIng = new ArrayList<String>();
		yellowRiceIng.add("milk");
		yellowRiceIng.add("egg");
		yellowRiceIng.add("wheat");
		yellowRiceIng.add("soybean");
		yellowRiceIng.add("tree nuts");
		yellowRiceIng.add("fish");
		YellowRice.setIngredients(yellowRiceIng);
		YellowRice.setProtein(4);
		YellowRice.setServing_size("1/4 Cup");
		YellowRice.setSodium(820);
		YellowRice.setTotal_carbs(36);
		YellowRice.setSugars(5);
		YellowRice.setTotal_fat(0);
		
		foodItems.add(YellowRice);
		
		FoodItem NutriGrainBar = new FoodItem();
		NutriGrainBar.setFood_name("Blueberry Nutrigrain Bar");
		NutriGrainBar.setBarcode("3800035700");
		NutriGrainBar.setCalories(120);
		NutriGrainBar.setCholesterol(0);
		ArrayList<String> nutriGrainIng = new ArrayList<String>();
		nutriGrainIng.add("milk");
		nutriGrainIng.add("wheat");
		nutriGrainIng.add("soybean");
		NutriGrainBar.setIngredients(nutriGrainIng);
		NutriGrainBar.setProtein(2);
		NutriGrainBar.setServing_size("1 Bar");
		NutriGrainBar.setSodium(110);
		NutriGrainBar.setTotal_carbs(24);
		NutriGrainBar.setSugars(5);
		NutriGrainBar.setTotal_fat(3);
		
		foodItems.add(NutriGrainBar);
		
		FoodItem FruitSnack = new FoodItem();
		FruitSnack.setFood_name("Thomas & Friends Fruit Snacks");
		FruitSnack.setBarcode("1600042225");
		FruitSnack.setCalories(80);
		FruitSnack.setCholesterol(0);
		ArrayList<String> fruitSnackIng = new ArrayList<String>();
		fruitSnackIng.add("corn starch");
		FruitSnack.setIngredients(fruitSnackIng);
		FruitSnack.setProtein(0);
		FruitSnack.setServing_size("1 Pouch");
		FruitSnack.setSodium(30);
		FruitSnack.setTotal_carbs(19);
		FruitSnack.setSugars(5);
		FruitSnack.setTotal_fat(0);
		
		foodItems.add(FruitSnack);
	}
	
	public ArrayList<FoodItem> getFoodItems() {
		return foodItems;
	}
	public ArrayList<FoodItem> searchFoodItems(String name, String barcode) {
	    ArrayList<FoodItem> results = new ArrayList<FoodItem>();
	    if (name != null) {
	        name = name.toLowerCase().trim();
	    }
	    for (FoodItem i : foodItems) {
	        if (name != null && i.getFood_name().toLowerCase().indexOf(name) != -1) {
	            results.add(i);
	        } else if (barcode != null && i.getBarcode().equals(barcode)) {
	            results.add(i);
	        }
	    }
	    return results;
	}
	
	public FoodItem getFoodItem(String item_name) {
	    for (FoodItem i : foodItems) {
	        if (item_name.equals(i.getFood_name())) {
	            return i;
	        }
	    }
	    //should never get here
	    return null;
		
	}

	private static FoodItemDataBase inst = null;
	public static FoodItemDataBase getInstance() {
		if (inst == null) {
			inst = new FoodItemDataBase();
		}
		return inst;
	}
}
